#ifndef CORE_H
#define CORE_H

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

// 错误代码定义
typedef enum {
    SUCCESS = 0,
    ERR_NULL_PTR,
    ERR_MEMORY_ALLOC,
    ERR_DIMENSION_MISMATCH,
    ERR_INDEX_OUT_OF_RANGE,
    ERR_INVALID_CHANNELS,
    ERR_UNSUPPORTED_OPERATION
} ErrorCode;

// 跨平台类型定义
#if defined(__x86_64__) || defined(_M_X64)
    #define ARCH_X86
#elif defined(__aarch64__) || defined(__arm__)
    #define ARCH_ARM
#endif

// 动态数组结构
typedef struct {
    size_t capacity;
    size_t size;
    int32_t* data;
} IntArray;

// 矩阵结构
typedef struct {
    size_t rows;
    size_t cols;
    double* data;  // 行优先存储
} Matrix;

// 图像结构
typedef struct {
    uint32_t width;
    uint32_t height;
    uint8_t channels;
    uint8_t* data;  // 连续内存存储
} Image;

// 核心API
IntArray* int_array_create(size_t initial_capacity);
void int_array_free(IntArray* arr);
void int_array_push(IntArray* arr, int32_t value);
int32_t int_array_get(const IntArray* arr, size_t index);

Matrix* matrix_create(size_t rows, size_t cols);
void matrix_free(Matrix* mat);
ErrorCode matrix_multiply(const Matrix* a, const Matrix* b, Matrix** result);

Image* image_create(uint32_t width, uint32_t height, uint8_t channels);
void image_free(Image* img);
ErrorCode image_grayscale(const Image* src, Image** dest);

// 内存对齐接口
void* aligned_alloc(size_t size);
void aligned_free(void* ptr);
bool is_aligned(const void* ptr);

#endif // CORE_H